<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余 <strong>{{ num }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: selectType === 'all' }"
          @click="changeType('all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'do' }"
          @click="changeType('do')"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: selectType === 'done' }"
          @click="changeType('done')"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear" v-show="isShow">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  props: {
    arr: {
      type: Array,
      require: true,
    },
  },
  data() {
    return {
      selectType: "all",
    };
  },
  computed: {
    num() {
      return this.arr.filter((item) => !item.isDone).length;
    },
    isShow() {
      return this.arr.some((item) => item.isDone);
    },
  },
  methods: {
    changeType(type) {
      this.selectType = type;
      this.$emit("changeType", type);
    },
    clear() {
      this.$emit("clear");
    },
  },
};
</script>
